package com.sxm.yiwei.activitis;

import android.Manifest;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.sxm.yiwei.MainActivity;
import com.sxm.yiwei.MyReceiver;
import com.sxm.yiwei.R;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;

/**
 * For developer startup JPush SDK
 * 一般建议在自定义 Application 类里初始化。也可以在主 Activity 里。
 *
 */
public class ExampleApplication extends Application implements AMapLocationListener {
    private static final String TAG = "home";
    private double latitude;
    private double longitude;
    private String city;
    private SharedPreferences sharedPreferences;
    private TelephonyManager telephonyManager;

    @Override
    public void onCreate() {
         super.onCreate();
         JPushInterface.setDebugMode(true); 	// 设置开启日志,发布时请关闭日志
        JPushInterface.init(this);     		// 初始化 JPush
        x.Ext.init(this);

        getLoc();
    }


    // 获取位置信息 经纬度
    public void getLoc() {
        AMapLocationClient client = new AMapLocationClient(getApplicationContext());
        AMapLocationClientOption option = new AMapLocationClientOption();
        option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        option.setInterval(300000);
        client.setLocationListener(this);
        client.setLocationOption(option);
        client.startLocation();
    }
    @Override
    public void onLocationChanged(AMapLocation aMapLocation) {
        // 获取定位信息
        latitude = aMapLocation.getLatitude();
        longitude = aMapLocation.getLongitude();
        city = aMapLocation.getCity();
        sharedPreferences = getSharedPreferences("userlogin", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("latitude",String.valueOf(latitude));
        edit.putString("longitude",String.valueOf(longitude));
        edit.putString("city", city);
        edit.commit();
    }
}
